<?php
/**
 * Prado Portal.
 *
 * @author Domingo Añez <domingo.aab@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2007,2008 Domingo Añez
 * @license http://www.pradoportal.dk
 * @version $Id: SearchPortlet.php 271 2008-11-07 07:56:57Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Portlets.Portlet');
class SearchPortlet extends Portlet
{
	const PORTLET_CONFIG_PREFIX	= "searchportlet_";

	private	$_portletconfig = null;

	public function getPortletConfig()
	{
		return $this->_portletconfig;
	}

	public function setPortletConfig($value)
	{
		$this->_portletconfig	= $value;
	}

	public function getConfigName()
	{
		return self::PORTLET_CONFIG_PREFIX . $this->Parameters['id'];
	}

	public function onInit($param)
	{
		parent::onInit($param);

		$crow = $this->DataAccess->createCommand("select * from tblconfig where name='{$this->ConfigName}'")->queryRow();
		if(!$crow)
		{
			$value	= serialize(array("outputcontrol" => ""));
			$this->DataAccess->createCommand("insert into tblconfig(name,value) values('{$this->ConfigName}','$value')")->execute();
			$crow = $this->DataAccess->createCommand("select * from tblconfig where name='{$this->ConfigName}'")->queryRow();
		}
		$this->_portletconfig = unserialize($crow['value']);
		$this->_portletconfig['id'] = $crow['id'];
	}

	public function onLoad($param)
	{
		$op = array();
		$op[] = array("id"=> 0,"name" => Prado::localize("Select"));

		foreach($this->Application->getLayoutAreas() as $la)
		{
			$op[] = $la;
		}

		$this->outputcontrol->DataSource = $op;
		$this->outputcontrol->dataBind();

		try
		{
			$this->outputcontrol->SelectedValue = $this->PortletConfig['outputcontrol'];
		}
		catch(Exception $e)
		{
			$this->outputcontrol->SelectedValue = 0;
		}
	}

	public function SaveSearchOptionsButton($sender,$param)
	{
		$value	= serialize(array("outputcontrol" => $this->outputcontrol->SelectedValue));
		$this->DataAccess->createCommand("update tblconfig set value='$value' where id={$this->PortletConfig['id']}")->execute();
	}
}
?>